package com.ruoyi.web;

import io.swagger.models.auth.In;
import lombok.Data;

/**
 * 微信搜 JavaGuide 回复"面试突击"即可免费领取个人原创的 Java 面试手册
 *
 * @author Guide哥
 * @date 2022/08/03 13:40
 **/
public class VolatileAtomicityDemo {
    public static void main(String[] args) {

        House house = new House();

        house.addLocal();

        System.out.println(house.getLocal());

    }

    @Data
    static class House {

        private int num;

        ThreadLocal<Integer> local = new ThreadLocal<>();

        public synchronized void add() {
            ++num;
        }

        public void addLocal() {
            local.set(1);
        }

        public Integer getLocal() {
            return local.get();
        }
    }
}
